// ID: B0100
package git.bankview.wl.bean;

import java.util.*;
import java.sql.*;

import git.bankview.sl.*;
import git.bankview.sl.db.*;

public class CommonFunc
{
	public static StringBuffer appendField(StringBuffer dest, String oValue, int nFieldType)
	{
		if (null == oValue || 0 == oValue.length())
			oValue = "";
		
		switch(nFieldType)
		{
			case Globals.FIELD_TYPE_TEXT:
			case Globals.FIELD_TYPE_DATE:
			{
				return dest.append("'").append(oValue).append("'");
			}
			case Globals.FIELD_TYPE_INTEGER:
			case Globals.FIELD_TYPE_DECIMAL:
			{
				return dest.append(oValue);
			}
		}
		
		throw new IllegalArgumentException("wrong field type code: " + nFieldType);
	}
	
	public static List getFieldInfoList(Connection conn, String tableName)
		throws Exception
	{
		StringBuffer oSql = new StringBuffer();
		oSql.append("SELECT dit.tablelabel")
			.append(", dit.tabledesc")
			.append(", dif.fieldname")
			.append(", dif.fieldtype")
			.append(", dif.fieldlabel")
			.append(", dif.fielddesc")
			.append(", dif.isprimarykey")
			.append(", dif.labelorder")
			.append(" FROM DqInfoTa dit, DqInfoFi dif")
			.append(" WHERE dit.tablename = '").append(tableName).append("'")
			.append(" AND dit.tablename = dif.tablename")
			.append(" ORDER BY dif.labelorder");
		
		Vector v = new Vector();
		DBUtil.simpleSQLExecute(v, oSql.toString(), 0, 0, conn);
		
		return v;
	}
}
